<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>用户登录</title>
    <!-- Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="../vendors/bootstrap/dist/css/bootstrap.min.css">
    <style>
        /*web background*/
        .container {
            display: table;
            height: 100%;
        }

        .row {
            display: table-cell;
            vertical-align: middle;
        }

        /* centered columns styles */
        .row-centered {
            text-align: center;
            width: 300px;
        }

    </style>
    <style>
        body {
            background: #F7F7F7;
        }
    </style>
</head>

<body>
<div class="container">
    <div class="row row-centered">
        <form id="form-edit">
            <div id="alertBlock"></div>
            <input type="hidden" name="uid" id="uid-edit"/>
            <div class="input-group input-group-md">
                <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                <input type="password" class="form-control" id="old-password" name="oldPassword" placeholder="请输入旧密码"/>
            </div>
            <br/>
            <br/>
            <div class="input-group input-group-md">
                <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                <input type="password" class="form-control" id="new-password" name="newPassword" placeholder="请输入新密码"/>
            </div>
            <br/>
            <br/>

        </form>
        <button class="btn btn-success btn-block" id="submit">修改</button>
    </div>
</div>


<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="../vendors/jquery/dist/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>

<!--myself script-->
<script src="../../vendors/myself/myself.js"></script>

<script type="text/javascript">
    $(function () {
        $.ajax('/user/getLoginedUser', {
            success: function (data) {
                $('#uid-edit').val(data.rows.uid);
                console.log(data.rows.uid);
            },
        })
    });

    $('#submit').click(function () {
        var formData = $('#form-edit').serializeObject();
        $.ajax('/user/changePassword', {
            type: 'post',
            data: formData,
            success: function (data) {
                if (data.code != 100) {
                    $('#alertBlock').html('<div id="myAlert" class="alert alert-info"> <a href="#" class="close" data-dismiss="alert">&times;</a> <strong>提示！</strong>修改成功。 </div>');
                } else {
                    $('#alertBlock').html('<div id="myAlert" class="alert alert-warning"> <a href="#" class="close" data-dismiss="alert">&times;</a> <strong>警告！</strong>' + data.msg + '。 </div>');
                }
            }
        });
    });
</script>

</body>
</html>
